<?php
$GLOBALS['basePath'] = '../';
try {
	require_once '../class/PHONGBAN.php';
	require_once '../class/common.php';

	$values = array();
	$errors = array();
	
	// POST
	if (isset($_POST["Submit"])) {
		$values = $_POST;
		$errors = PHONGBAN::Validate($values);
		
		if (empty($errors))	{
			PHONGBAN::Create($values);
			Redirect("index.php");
		}
	}
} catch (Exception $e) {
	Redirect("/error.php");			
}
EchoHeader('Phòng ban', 'department');
?>
<script type="text/javascript">
	$(function () {
		// highlight textbox
		$(':text').focus(function () {
			$(this).addClass('selected');
		});
		$(':text').blur(function () {
			$(this).removeClass('selected');
		});

		// form field hint
		$('.hint').append('<span class="pointer">&nbsp;</span>');
		$(':text, :checkbox, :password, select, :radio').focus(function () {
			$(this).parent().children('.hint').show();
		});
		$(':text, :checkbox, :password, select, :radio').blur(function () {
			$(this).parent().children('.hint').hide();
		});
	});
</script>	
<div class="primary box">
	<div class="box-inside">
		<div class="heading"><h2>Thêm phòng ban</h2></div>
		<div class="content">
		<form method="post" name="frmPhongBan" onSubmit="return onPhongBanSubmit()">
		<fieldset>
			<!-- TenPhong -->
			<div class="field">
				<div class="label"><label for="TenPhong">Tên Phòng</label></div>
				<div class="input">
					<input type="text" name="TenPhong" id="TenPhong" value="<?php echo GetValue($values, "TenPhong"); ?>" <?php echo GetErrorClass($errors, "TenPhong"); ?>/>
					<?php echo GetError($errors, "TenPhong"); ?><span class="hint">Tên của phòng ban, duy nhất</span>
				</div>
			</div>
		</fieldset>
		
		<input type="submit" name="Submit" value="Thêm" class="button"/>
		<a href="index.php" class="button">Hủy</a>
		</form>
		</div>
	</div>
</div>
<?php EchoFooter(); ?>